'use strict';
stareal
    .controller("CategoryList", function ($rootScope,$scope, $api, $stateParams, $alert, $document, localStorageService, $state, $interval,$lazyLoader) {
           $scope.currentClassfyId=$stateParams.classId;
           $scope.kind=$stateParams.hos;
        var h=$(window).height()-3.0*parseFloat(document.documentElement.style.fontSize)+"px";
        $("#wrapper_container").height(h);
        var tabSubSwiper = new Swiper('#Tab_ccontent', {
            freeMode: true,
            slidesPerView: 'auto',
            spaceBetween:0,
            freeModeSticky: true,
            observer:true,//修改swiper自己或子元素时，自动初始化swiper
        })
        // 今日推荐
        $api.get("app/view/recommends",{flag:1}, true)
            .then(function(ret){
                $scope.recommends = ret.data;
            })
        // 分类更多
        $scope.getMoreclassifyli=function(){
                if($scope.currentClassfyId==0){
                    $scope.goods = new $lazyLoader("app/view/classifyli",
                        {id:"",hos:$scope.kind,flag:1}, true);
                    $scope.goods.nextPage();
                }else{
                    $scope.goods = new $lazyLoader("app/view/classifyli",
                        {id:$scope.currentClassfyId,hos:$scope.kind,flag:1}, true);
                    $scope.goods.nextPage();
                }
        }
        var refresh = function(kid){
            $state.go('main.pm_CategoryList',{classId:kid,hos:$scope.kind},true);
        };
        // 分类列表
        $api.get("app/view/classifylist",{}, true)
            .then(function(ret){
                var data=ret.data;
                var obj={id:'0',img:'',name:'全部'};
                data.unshift(obj);
                for(var i=0;i<data.length;i++){
                    if(data[i].id==$scope.currentClassfyId){
                        $scope.currentIndex=i;
                    }
                }
                $scope.classifylistids = data;
                $scope.getMoreclassifyli();
            })


        // 点击导航栏
        $scope.switch = function(kind,index){
            $scope.currentClassfyId=kind;
            $scope.currentIndex=index;
            refresh(kind);
        };
        $scope.filter=function(indx){
            $scope.kind=indx;
            refresh($scope.currentClassfyId);
        }
        $scope.$on("navFinishRender",function(){
            $('#demo05').navbarscroll({
                defaultSelect:$scope.currentIndex,
            });
        })

    })




